/*
 * Copyright (C) 2018 Logos Technology Ltd.
 */

package com.logos.tool;

import com.google.gson.Gson;
import com.google.gson.TypeAdapter;
import com.google.gson.TypeAdapterFactory;
import com.google.gson.reflect.TypeToken;

/**
 * Created by hk on 2018/10/15.
 */
public class NullStringToEmptyAdapterFactory<T> implements TypeAdapterFactory {
    /**
     * create
     *
     * @param gson gson
     * @param type type
     * @param <T>  T
     * @return T
     */
    @SuppressWarnings("unchecked")
    public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
        Class<T> rawType = (Class<T>) type.getRawType();
        if (rawType != String.class) {
            return null;
        }
        return (TypeAdapter<T>) new StringNullAdapter();
    }
}
